<?php

namespace app\common\order\logic;

use app\common\BaseLogic;
use app\common\order\model\Suborder;

class SuborderLogic extends BaseLogic
{

    // 统计
    public function statistics($userIds, $dateRange) {
      
        $model = new Suborder();
        $where = [];
        $where[] = ['user_id', 'in', $userIds];
        $where[] = ['create_time', 'between', $dateRange];
        $amount = $model->where($where)->count();
        $totals = $model->where($where)->sum('totals');

        $data = [
           [
               'title' => '订单总数',
               'total' => $amount
           ],
           [
               'title' => '订单总金额',
               'total' => number_format(sprintf("%.2f", $totals))
           ]
        ];
        
        return $data;
    }
}